<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>重点青少年人员信息</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="element.css">
</head>
<body>
<div id="app" style="width: 80%; margin: 0 auto">
    <h2>重点青少年人员信息</h2>

    <el-row>
        <el-col :span="6" style="margin-bottom: 10px">
            <el-button type="primary" @click="add">新增</el-button>
            <el-input v-model="name" style="width: 70%" @keyup.enter.native="loadTable(1)"></el-input>
        </el-col>
    </el-row>

    <el-table
            :data="page.content"
            stripe
            border
            style="width: 100%">
        <el-table-column
                prop="name"
                label="用户名"
        >
        </el-table-column>
        <el-table-column
                prop="idNumber"
                label="身份证号"
                width="180">
        </el-table-column>
        <el-table-column
                prop="gender"
                label="性别">
        </el-table-column>
        <el-table-column
                prop="contactPhone"
                label="手机号">
        </el-table-column>
        <el-table-column
                prop="personType"
                label="人员类型">
        </el-table-column>
        <el-table-column
                prop="familySituation"
                label="家庭情况">
        </el-table-column>
        <el-table-column
                prop="guardianIdNumber"
                label="监护人身份证">
        </el-table-column>
        <el-table-column
                prop="guardianName"
                label="监护人姓名">
        </el-table-column>
        <el-table-column
                prop="relationshipWithGuardian"
                label="与监护人关系">
        </el-table-column>
        <el-table-column
                prop="guardianContactPhone"
                label="监护人电话">
        </el-table-column>
        <el-table-column
                prop="guardianAddress"
                label="监护人住址">
        </el-table-column>
        <el-table-column
                prop="hasIllegalBehavior"
                label="是否违法犯罪">
        </el-table-column>
        <el-table-column
                prop="illegalBehaviorDetails"
                label="违法犯罪情况">
        </el-table-column>
        <el-table-column
                prop="helperName"
                label="帮扶人姓名">
        </el-table-column>
        <el-table-column
                prop="helperContactPhone"
                label="帮扶人电话">
        </el-table-column>
        <el-table-column
                prop="assistanceMeasures"
                label="帮扶手段">
        </el-table-column>
        <el-table-column
                fixed="right"
                label="操作"
                width="100">
            <template slot-scope="scope">
                <el-button type="primary" icon="el-icon-edit" size="small" circle @click="edit(scope.row)"></el-button>
                <el-button type="danger" icon="el-icon-delete" size="small" circle @click="del(scope.row.id)"></el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-row type="flex" justify="center" style="margin-top: 10px">
        <el-pagination
                layout="prev, pager, next"
                :page-size="pageSize"
                :current-page="pageNum"
                @prev-click="loadTable"
                @current-change="loadTable"
                @next-click="loadTable"
                :total="page.totalElements">
        </el-pagination>
    </el-row>

    <el-dialog
            title="用户信息"
            :visible.sync="dialogVisible"
            width="40%">
        <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="用户名">
                <el-input v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item label="身份证号">
                <el-input v-model="form.idNumber"></el-input>
            </el-form-item>
            <el-form-item label="性别" prop="gender">
                <el-select v-model="form.gender" placeholder="请选择性别">
                    <el-option label="男" value="男"></el-option>
                    <el-option label="女" value="女"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="联系电话">
                <el-input v-model="form.contactPhone"></el-input>
            </el-form-item>
            <el-form-item label="人员类型">
                <el-select v-model="form.personType" placeholder="请选择人员类型">
                    <el-option label="闲散青少年" value="闲散青少年"></el-option>
                    <el-option label="不良行为青少年" value="不良行为青少年"></el-option>
                    <el-option label="流浪乞讨未成年" value="流浪乞讨未成年"></el-option>
                    <el-option label="服役人员未成年子女" value="服役人员未成年子女"></el-option>
                    <el-option label="农村留守儿童" value="农村留守儿童"></el-option>
                    <el-option label="其他" value="其他"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="家庭情况">
                <el-select v-model="form.familySituation" placeholder="请选择家庭情况">
                    <el-option label="低收入家庭" value="低收入家庭"></el-option>
                    <el-option label="单亲家庭" value="单亲家庭"></el-option>
                    <el-option label="流动家庭" value="流动家庭"></el-option>
                    <el-option label="抚养人受教育水平相对较低" value="抚养人受教育水平相对较低"></el-option>
                    <el-option label="与父母关系不融洽" value="与父母关系不融洽"></el-option>
                    <el-option label="家庭成员的不良行为多" value="家庭成员的不良行为多"></el-option>
                    <el-option label="其他" value="其他"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="监护人身份证">
                <el-input v-model="form.guardianIdNumber"></el-input>
            </el-form-item>
            <el-form-item label="监护人姓名">
                <el-input v-model="form.guardianName"></el-input>
            </el-form-item>
            <el-form-item label="与监护人关系">
                <el-input v-model="form.relationshipWithGuardian"></el-input>
            </el-form-item>
            <el-form-item label="监护人电话">
                <el-input v-model="form.guardianContactPhone"></el-input>
            </el-form-item>
            <el-form-item label="监护人住址">
                <el-input v-model="form.guardianAddress"></el-input>
            </el-form-item>
            <el-form-item label="是否违法犯罪">
                <el-input v-model="form.hasIllegalBehavior"></el-input>
            </el-form-item>
            <el-form-item label="违法犯罪情况">
                <el-input v-model="form.illegalBehaviorDetails"></el-input>
            </el-form-item>

            <el-form-item label="帮扶人姓名">
                <el-input v-model="form.helperName"></el-input>
            </el-form-item>
            <el-form-item label="帮扶人电话">
                <el-input v-model="form.helperContactPhone"></el-input>
            </el-form-item>
            <el-form-item label="帮扶手段">
                <el-select v-model="form.assistanceMeasures" placeholder="请选择活动区域">
                    <el-option label="教育矫治" value="教育矫治"></el-option>
                    <el-option label="思想引导" value="思想引导"></el-option>
                    <el-option label="困难帮扶" value="困难帮扶"></el-option>
                    <el-option label="心里关爱" value="心里关爱"></el-option>
                    <el-option label="其他" value="其他"></el-option>
                </el-select>
            </el-form-item>

        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="save">确 定</el-button>
        </span>
    </el-dialog>

</div>

<script src="jquery.min.js"></script>
<script src="vue.js"></script>
<!-- 引入组件库 -->
<script src="element.js"></script>

<script>
    new Vue({
        el: '#app',
        data: {
            page: {},
            name: '',
            pageNum: 1,
            pageSize: 8,
            dialogVisible: false,
            form: {}
        },
        created() {
            this.loadTable(this.pageNum);
        },
        methods: {
            loadTable(num) {
                this.pageNum = num;
                $.get("/tset/page?pageNum=" + this.pageNum + "&pageSize=" + this.pageSize + "&name=" + this.name).then(res => {
                    this.page = res.data;
                });
            },
            add() {
                this.dialogVisible = true;
                this.form = {};
            },
            edit(row) {
                this.form = row;
                this.dialogVisible = true;
            },
            save() {
                let data = JSON.stringify(this.form);
                if (this.form.id) {
                    // 编辑
                    $.ajax({
                        url: '/tset',
                        type: 'put',
                        contentType: 'application/json',
                        data: data
                    }).then(res => {
                        this.dialogVisible = false;
                        this.loadTable(1);
                    })
                } else {
                    // 新增
                    $.ajax({
                        url: '/tset',
                        type: 'post',
                        contentType: 'application/json',
                        data: data
                    }).then(res => {
                        this.dialogVisible = false;
                        this.loadTable(1);
                    })
                }
            },
            del(id) {
                $.ajax({
                    url: '/tset/' + id,
                    type: 'delete',
                    contentType: 'application/json'
                }).then(res => {
                    this.loadTable(1);
                })
            }
        }
    })
</script>
</body>
</html>
